package com.jsmy.marketing.adapter;


import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jsmy.marketing.R;
import com.jsmy.marketing.activity.CustomerActivity;
import com.jsmy.marketing.bean.TXLBean;
import com.jsmy.marketing.utils.NetWork;


/**
 * Created with Android Studio.
 * User: wei_cd.
 * Date: 2018/4/23.
 * Time: 17:19.
 * To change for file | settings | file and code templates.
 */

public class DataItemAdapter extends BaseQuickAdapter<TXLBean.DataBean.ListBeanX.ListBean, BaseViewHolder> {

    public DataItemAdapter() {
        super(R.layout.fragment_data_item_child);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final TXLBean.DataBean.ListBeanX.ListBean item) {
        helper.setText(R.id.tv_title, item.getXm())
                .setText(R.id.tv_phone, item.getDh())
                .setText(R.id.tv_plant, "最新计划："+item.getPlan())
         .setText(R.id.tv_content, item.getNote());
        helper.getView(R.id.fg_data_item_child).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(helper.getView(R.id.tv_title).getContext(), CustomerActivity.class);
                intent.putExtra("kid",item.getKid());
                helper.getView(R.id.tv_title).getContext().startActivity(intent);

            }
        });
        NetWork.setImageGlide(helper.getView(R.id.tv_title).getContext(),item.getIco(),(ImageView) helper.getView(R.id.img));
        if (item.getJdid().equals("3")){
            helper.getView(R.id.btn_add_listener_test).setVisibility(View.VISIBLE);
        }else {
            helper.getView(R.id.btn_add_listener_test).setVisibility(View.GONE);
        }
        helper.addOnClickListener(R.id.btn_add_listener_test);
    }

    /**
     * 根据分类的首字母的Char ascii值获取其第一次出现该首字母的位置
     */
    public int getPositionForSection(int section) {
        for (int i = 0; i < getItemCount(); i++) {
            String sortStr = mData.get(i).getXm();
            char firstChar = sortStr.toUpperCase().charAt(0);
            if (firstChar == section) {
                return i;
            }
        }
        return -1;
    }
    /**
     * 根据ListView的当前位置获取分类的首字母的char ascii值
     */
    public int getSectionForPosition(int position) {
        return mData.get(position).getXm().charAt(0);
    }
}
